@using System.Threading


<MudPopoverProvider></MudPopoverProvider>

<MudDataGrid T="Item" VirtualizeServerData="ServerDataFunc" Virtualize="true" Filterable="true" ItemSize="53.68f" Height="300px">
    <Columns>
        <PropertyColumn Property="x => x.Name"/>
    </Columns>
</MudDataGrid>

@code {
    public static string __description__ = @"Test in-browser-filtering of DataGrid.";

    private IEnumerable<Item> _items = new List<Item>()
    {
        new Item("B"),
        new Item("A"),
        new Item("C"),
        new Item("C")
    };

    public record Item(string Name);

    private async Task<GridData<Item>> ServerDataFunc(GridStateVirtualize<Item> gridState, CancellationToken token)
    {
        await Task.CompletedTask;

        var filterFunctions = gridState.FilterDefinitions.Select(x => x.GenerateFilterFunction());
        var totalItems = _items
            .Where(x => filterFunctions.All(f => f(x)))
            .ToList();

        var limitedResult = totalItems
            .Skip(gridState.StartIndex)
            .Take(gridState.Count)
            .ToList();

        return new GridData<Item>
        {
            Items = limitedResult,
            TotalItems = totalItems.Count
        };
    }

}